#pragma once

#include "ConnectableElement.h"

#include "ConnectableElementTemplateParameter.h"
#include "ConnectorEnd.h"

namespace uml {

void ConnectableElement::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    ParameterableElement::fromJson(json, errorList);
    TypedElement::fromJson(json, errorList);
    JsonSerializable::fromJsonArray(ends_, "ends", json, errorList);
    templateParameter_ = JsonSerializable::create<ConnectableElementTemplateParameter>(json.value("templateParameter"), errorList);

}

void ConnectableElement::toJson(QJsonObject& json) {
    ParameterableElement::toJson(json);
    TypedElement::toJson(json);
    JsonSerializable::toJsonArray(ends_, "ends", json);
    if (templateParameter_) {
        QJsonObject templateParameter_json;
        templateParameter_->toJson(templateParameter_json);
        json.insert("templateParameter", templateParameter_json);
    }
}

/// <summary>
/// ends getter
/// A set of ConnectorEnds that attach to this ConnectableElement.
/// </summary>
vector<shared_ptr<ConnectorEnd>>& ConnectableElement::ends() {
    return ends_;
}

/// <summary>
/// templateParameter getter
/// The ConnectableElementTemplateParameter for this ConnectableElement parameter.
/// </summary>
shared_ptr<ConnectableElementTemplateParameter> ConnectableElement::templateParameter() const {
    return templateParameter_;
}

/// <summary>
/// templateParameter setter
/// The ConnectableElementTemplateParameter for this ConnectableElement parameter.
/// </summary>
void ConnectableElement::setTemplateParameter(shared_ptr<ConnectableElementTemplateParameter> value) {
    templateParameter_ = value;
}

} // namespace uml
